package org.ipower.platform.cfg;

import java.io.Serializable;  
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/*
 * 菜单模块定义集合。
 * */
public class ModuleDefineCollection  implements  Collection<ModuleDefine>,Comparator<ModuleDefine>, Serializable {
	private static final long serialVersionUID = 7052685958923104370L;
	private List<ModuleDefine> list = null;
	/*
	 * 构造函数。
	 * */
	public ModuleDefineCollection(){
		this.list = new ArrayList<ModuleDefine>();
	}
	
	@Override
	public int size() {
		return this.list.size();
	}

	@Override
	public boolean isEmpty() {
		return this.list.isEmpty();
	}

	@Override
	public boolean contains(Object o) {
		if(o == null)
			return false;
		return this.list.contains(o);
	}

	@Override
	public Iterator<ModuleDefine> iterator() {
		Collections.sort(this.list, this);
		return this.list.iterator();
	}

	@Override
	public Object[] toArray() {
		Collections.sort(this.list, this);
		return this.list.toArray();
	}

	@Override
	public <T> T[] toArray(T[] a) {
		Collections.sort(this.list, this);
		return this.list.toArray(a);
	}

	@Override
	public boolean add(ModuleDefine data) {
		if(data == null)
			return false;
		return this.list.add(data);
	}

	@Override
	public boolean remove(Object o) {
		if(o == null)
			return false;
		return this.list.remove(o);
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		if(c == null || c.size() == 0)
			return false;
		return this.list.containsAll(c);
	}

	@Override
	public boolean addAll(Collection<? extends ModuleDefine> c) {
	    if(c == null)
	    	return false;
	    return this.list.addAll(c);
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		if(c == null)
			return false;
		return this.list.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		if(c == null)
			return false;
		return this.list.retainAll(c);
	}

	@Override
	public void clear() {
		 this.list.clear();
	}
	@Override
	public int compare(ModuleDefine x, ModuleDefine y) {
		 if(x == null && y == null)
			 return 0;
		 else if(x == null)
			 return  -1;
		 else if(y == null)
			 return 1;
		 else
			 return x.getOrderNo() - y.getOrderNo();
	}
}
